<template>
  <div>
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <i class="el-icon-lx-cascades"></i> 基础表格
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div class="handle-box">
        <el-button
            type="primary"
            icon="el-icon-group"
            class="handle-del mr10"
            @click="delAllSelection"
        >选中按钮
        </el-button>
      </div>
      <el-table
          :data="PetData"
          border
          class="table"
          ref="multipleTable"
          header-cell-class-name="table-header"
          @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" align="center"></el-table-column>
        <el-table-column prop="id" label="表单ID" width="100" align="center"></el-table-column>
        <el-table-column prop="username" label="宠物名" width="200" align="center"></el-table-column>
        <el-table-column prop="toAddress" label="申请领养地址" align="center"></el-table-column>
        <el-table-column prop="others" label="说明" align="center"></el-table-column>
        <el-table-column label="审批情况" width="150" align="center">
          <template slot-scope="scope">
            <el-tag
                :type="scope.row.ifSuccess==='通过' ?'success':(scope.row.ifSuccess=== '不通过'?'danger':(scope.row.ifSuccess===''?'danger':''))"
            >{{ scope.row.ifSuccess }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column label="申请时间" align="center">
        <template slot-scope="scope">{{ scope.row.createTime.substr(0, 4) }}年{{ scope.row.createTime.substr(5, 5) }}日
          {{ scope.row.createTime.substr(11, 12) }}
        </template>
      </el-table-column>

      </el-table>
      <div class="pagination">
        <el-pagination
            background
            layout="total, prev, pager, next"
            :current-page="current"
            :page-size="query.pageSize"
            :total="totlalElement"
            @current-change="handlePageChange"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<script>
import axios from "axios";

export default {
  name: 'notVerify',
  data() {
    return {
      query: {
        pageIndex: 1,
        pageSize: 10
      },
      current: 1,
      totlalElement: 0,
      ifAdopt: "",
      name: "",
      real_size: 0,
      PetData: "",
      tableData: [],
      multipleSelection: [],
      delList: [],
      editVisible: false,
      pageTotal: 0,
      form: {},
      idx: -1,
      id: -1
    };
  },
  created() {
    this.showPets()
  },
  methods: {
    // 多选操作
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    delAllSelection() {
      const length = this.multipleSelection.length;
      let str = '';
      this.delList = this.delList.concat(this.multipleSelection);
      for (let i = 0; i < length; i++) {
        str += this.multipleSelection[i].name + ' ';
      }
      this.$message.success(`选中了${str}`);
      /*this.multipleSelection = [];*/
    },

    // 分页导航
    handlePageChange(val) {
      this.current = val
      this.showPets()
      console.log(`当前页: ${val}`);
    },
    showPets() {
      if(this.$store.state.userId==0){
        alert("请去登陆");
        this.$router.replace({path: '/login'});
      }
      axios
          .post(this.$store.state.url+":8412/petApply/getUserAdoptions?" +
              "userId=" + localStorage.getItem("myId") +
              "&current=" + this.current + "&size=" + this.query.pageSize)
          .then((data) => {
            console.log("查找宠物中。。。")
            console.log(data);
            this.PetData = data.data.data
            this.totalPage = data.data.totalPage
            this.totlalElement = data.data.totalElement
            if (this.totlalElement == 0) {
              alert("没有查到任何资料")
              this.real_size = 0;
            }
            this.real_size = data.data.data.length
            console.log(this.PetData)
          })
          .catch((err) => {
            console.log(err);
          });
    },
  }
};
</script>

<style scoped>
.handle-box {
  margin-bottom: 20px;
}

.table {
  width: 100%;
  font-size: 14px;
}

.mr10 {
  margin-right: 10px;
}

.table-td-thumb {
  display: block;
  margin: auto;
  width: 40px;
  height: 40px;
}
</style>
